/*
 * Copyright (c) 2011-2014, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: receiveFunction.c 7805 2014-03-13 09:54:35Z geisinger $
 */

/**
 * \file
 *         Source file for function receive in component subscriber.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (XMT)
 *         (fortiss GmbH).
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "configuratorExtension/adv/subscriber/include/receiveFunction.h"

#include "configuratorExtension/adv/subscriber/include/receiveFunctionWrapper.h"
#include "configuratorExtension/adv/subscriber/include/subscriberComponent.h"
#include "configuratorExtension/adv/subscriber/include/subscriberComponentWrapper.h"
#include "configuratorExtension/adv/subscriber/include/subscriberManifest.h"

#include "xme/core/logUtils.h"

#include "xme/hal/include/mem.h"

// PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_C_INCLUDES) ENABLED START

#include "configuratorExtension/topic/dictionary.h"

// PROTECTED REGION END

/******************************************************************************/
/***   Definitions                                                          ***/
/******************************************************************************/

// PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_C_DEFINITIONS) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Variables                                                            ***/
/******************************************************************************/

// PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_C_VARIABLES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/

// PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_C_PROTOTYPES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Implementation                                                       ***/
/******************************************************************************/
xme_status_t
configuratorExtension_adv_subscriber_receiveFunction_init
(
    configuratorExtension_adv_subscriber_subscriberComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_INITIALIZE_C) ENABLED START
    
    // Nothing to do
    
    XME_UNUSED_PARAMETER(componentConfig);
    
    return XME_STATUS_SUCCESS;
    
    // PROTECTED REGION END
}

void
configuratorExtension_adv_subscriber_receiveFunction_step
(
    configuratorExtension_adv_subscriber_subscriberComponent_config_t* const componentConfig
)
{
    xme_status_t status[1];
    
    configuratorExtension_topic_data_t portInData; // Required port.
    
    (void)xme_hal_mem_set(&portInData, 0u, sizeof(configuratorExtension_topic_data_t));
    
    status[0] = configuratorExtension_adv_subscriber_subscriberComponentWrapper_readPortIn(&portInData);
    
    {
        // PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_STEP_C) ENABLED START
        
        configuratorExtension_attribute_quality_t quality;

        XME_UNUSED_PARAMETER(componentConfig);
        XME_UNUSED_PARAMETER(status);

        (void) configuratorExtension_adv_subscriber_subscriberComponentWrapper_readInputPortAttribute
        (
            (configuratorExtension_adv_subscriber_subscriberComponentWrapper_internalPortId_t)
                CONFIGURATOREXTENSION_ADV_SUBSCRIBER_SUBSCRIBERCOMPONENTWRAPPER_PORT_IN,
            (xme_core_attribute_key_t) CONFIGURATOREXTENSION_ATTRIBUTE_QUALITY,
            &quality,
            sizeof(quality)
        );

        XME_LOG_C(XME_CORE_COMPONENT_TYPE_SUBSCRIBER, XME_LOG_ALWAYS, "received: %d (quality %d)\n", portInData.value, quality);
        
        // PROTECTED REGION END
    }
    
    {
        // PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_STEP_2_C) ENABLED START
        
        // Nothing to do
        
        // PROTECTED REGION END
    }
}

void
configuratorExtension_adv_subscriber_receiveFunction_fini
(
    configuratorExtension_adv_subscriber_subscriberComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_TERMINATE_C) ENABLED START
    
    // Nothing to do
    
    XME_UNUSED_PARAMETER(componentConfig);

    // PROTECTED REGION END
}

// PROTECTED REGION ID(CONFIGURATOREXTENSION_ADV_SUBSCRIBER_RECEIVEFUNCTION_IMPLEMENTATION_C) ENABLED START

// PROTECTED REGION END
